/*
 * Created on Oct 13, 2005 8:02:45 AM
 * 
 * $Id: UnixWriteHandle.java,v 1.1 2005/10/16 14:14:58 olu Exp $
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package tripleo.framework.fs;

import java.io.FileOutputStream;
import java.io.IOException;

import tripleo.framework.io.ReadableByteStream;
import tripleo.fs.File;

final class UnixWriteHandle implements WriteHandle {
	/**
	 * 
	 */
	private final UnixFileDesc mDesc;
	private FileOutputStream fos;
	private File mBacking;

	public File backing() { return mBacking; }
	
	public UnixWriteHandle(UnixFileDesc aDesc) throws FileOpFailure  {
		mDesc = aDesc;
		try {
			mBacking = new File(mDesc.getPath());
			fos=mBacking.fos();
		} catch (IOException e) {
			throw new FileOpFailure(e);
		}
	}

	public void write(ReadableByteStream aByteStream) throws FileOpFailure {
		try {
			fos.write(aByteStream.array());
		} catch (IOException e) {
			throw new FileOpFailure(e);
		}
	}

	public void close() throws FileOpFailure {
		try {
			fos.close();
		} catch (IOException e) {
			throw new FileOpFailure(e);
		}
	}
}
